<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/transaction/one.css">
</script>
        <div id="EditContent" class="layui-fluid layui-alert-box">  
        </div>
        <div class="footer layui-btn-container">
            <button class="end layui-btn layui-btn-radius layui-btn-primary layui-btn-container"  id="confirm_one">确认</button>
            <button class="out layui-btn-container layui-btn-radius layui-btn-primary"  id='cancel_one'>取消</button>
        </div>
    <style scoped> 
    #EditContent {
        overflow-y: scroll;
        height: 80%
    }
    
    .selected>div:first-of-type span {
        color: red !important;
    }
    .layui-fluid {
        padding: 0px !important
    }
    </style> 
    <script> 
    
        var TransmitData = {};  
         layui.use(['layer','element','setter','tree','jquery'], function() {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$,
                admin = layui.admin,
                view = layui.view,
                api = layui.api,
                table = layui.table,
                setter = layui.setter,
                laytpl = layui.laytpl,
                tree = layui.tree,
                utill = layui.utill,
                form = layui.form,
                element = layui.element;  
                layui.sessionData('one_data', null);
                var onedata=null
                   $.ajax({
                        type: "GET",
                        url: api.host + api.sbwd.doSelectOption,  
                        data: {},
                        headers: {
                            'Content-Type': 'application/json',
                            'token': layui.sessionData(setter.tableName).token 
                        },
                        async: false,
                        dataType: "json",
                        jsonp: "callback", //传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback) 
                        success: function(data) { 
                            if (data.code == '0') {
                                var odata = data.data 
                                function transferKey(odata) {
                                    odata.forEach(obj => {
                                        obj.title = obj.tcCatgName
                                        obj.children = obj.childList
                                        delete obj["tcCatgName"]
                                        delete obj["childList"]
                                        if (obj.children instanceof Array) {
                                            transferKey(obj.children)
                                        }
                                    })
                                    return odata
                                }
                                odataArr = transferKey(odata) 
                                var inst1 = tree.render({
                                    elem: '#EditContent', //传入元素选择器
                                    skin: 'sidebar'  ,  //自定义tree样式的类名
                                    showLine: false, //是否开启连接线
                                    // edit:true,
                                    id:'TESTid',
                                    data: odataArr,
                                    onlyIconControl: true,
                                    click: function(obj) {
                                        TransmitData['date'] = obj.data
                                        $('div').removeClass('selected')
                                        obj.elem[0].classList.add('selected')
                                        onedata=obj.data     
                                    } 
                                }) 
                            } else {
                                layer.msg(data.message, {
                                    icon: 5
                                });
                            }
                        }
                    }) 
            $('.footer').on('click', 'button', function() {
                var index = parent.layer.getFrameIndex(window.name); 
                if($(this).html()=='确认'){ 
                    if(onedata!=''){  
                        layui.sessionData('one_data', {
                            key:'odata',
                            value:onedata
                        }) 
                        parent.layer.close(index);  
                        layer.close( sessionStorage.getItem('index'))
                    }
                }else{ 
                    parent.layer.close(index);  
                    layer.close( sessionStorage.getItem('index'))
                }
            }); 
         })
        
    </script> 